﻿using System;

namespace UnsafeCodeApplication
{
    class TestPointer
    {
        public unsafe void Swap(int* p, int* q) // 传递指针作为方法的参数
        {
            int temp = *p;
            *p = *q;
            *q = temp;
        }

        public unsafe static void Main()
        {
            TestPointer p = new TestPointer();
            int var1 = 10;
            int var2 = 20;
            int* x = &var1;
            int* y = &var2;

            Console.WriteLine("Before Swap: var1: {0}, var2: {1}", var1, var2);
            p.Swap(x, y);

            Console.WriteLine(" After Swap: var1: {0}, var2: {1}", var1, var2);
            Console.ReadKey();
        }
    }
}